home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / CHIP Haziran 2001.iso / prog / share / 04 / setup.exe / MM27.Cab / F855_JSA.h.0162E57D_7C98_4D94_A1CA_6231808F03E6 < prev    next >
Text File  |  2000-09-14  |  10KB  |  290 lines

  1. /*************************************************************************
  2. *
  3. * ADOBE CONFIDENTIAL
  4. * ___________________
  5. *
  6. *  Copyright 2000 Adobe Systems Incorporated
  7. *  All Rights Reserved.
  8. *
  9. * NOTICE:  All information contained herein is, and remains the property of 
  10. * Adobe Systems Incorporated  and its suppliers, if any.  The  intellectual 
  11. * and technical concepts contained herein are proprietary to  Adobe Systems 
  12. * Incorporated a nd its suppliers  and may be covered by U. S. and  Foreign 
  13. * Patents,patents in process,and are protected by trade secret or copyright 
  14. * law.  Dissemination of this information or reproduction  of this material
  15. * is strictly forbidden  unless prior  written permission  is obtained from 
  16. * Adobe Systems Incorporated.
  17. *
  18. **************************************************************************/
  19.  
  20. /* ----------------------------------------------------------------
  21. // JSA.h
  22. // Definitions for the GoLive Extend Script SDK
  23. // -------------------------------------------------------------- */
  24.  
  25. #ifndef _JSA_H_
  26. #define _JSA_H_
  27.  
  28. /* The JSA Javascript Interface
  29. The JSA interface permits developers to write binary code extensions for the Extend Script SDK.
  30. All modules must reside in the SDK subdirectory Common, and all functions are callable by all
  31. Javascript extension modules. The functions are accessible as parts of a Javscript object
  32. which has the same name as the DLL or SharedLib. If, for example, the DLL is called "SomeExt.DLL",
  33. and it contains a function "foo", the function is callable as "SomeExt.foo()".
  34.  
  35. See the documentation for further information.
  36.  
  37. When writing a module, it is important to implement the macro JSA_INIT once which defines some data
  38. structures and performs the necessary initialization of the module.
  39. */
  40.  
  41. #ifdef __cplusplus
  42.  
  43. extern "C" {                
  44. #endif                        
  45.  
  46. /**
  47. All data elements are opaque void pointers which are casted internally.
  48. */
  49.  
  50. typedef void *JSValue;
  51.  
  52. /**
  53. The supplied data is one of the following scalar types, returned by JSAGetValueType().
  54. */
  55.  
  56. enum JSAValueType {
  57.     /** Undefined or empty value. */
  58.     JSA_UNDEFINED,
  59.     /** A boolean value,either 0 or 1. */
  60.     JSA_BOOL,
  61.     /** A 32 bit signed integer quantity. */
  62.     JSA_INTEGER,
  63.     /** An 8 byte double precision floating point value. */
  64.     JSA_DOUBLE,
  65.     /** A null-terminated ASCII string. */
  66.     JSA_STRING
  67. };
  68.  
  69. /**
  70. All callable functions must be encoded as JSANativeMethods. They receive
  71. an argc/argv combination as well as a location to store the return value.
  72. @param    argc    the number of arguments
  73. @param    argv    the argument vector
  74. @param    retval    a location to store any return value, preset to undefined
  75. */
  76. typedef void (*JSANativeMethod)(int argc, JSValue *argv, JSValue returnValue);
  77.  
  78. typedef int    (*JSAValueTypeFct)(void *, JSValue);
  79. typedef long   (*JSAValueToIntFct)(void *, JSValue);
  80. typedef void   (*JSAIntToValueFct)(void *, long, JSValue);
  81. typedef int    (*JSAValueToBoolFct)(void *, JSValue);
  82. typedef void   (*JSABoolToValueFct)(void *, int, JSValue);
  83. typedef char*  (*JSAValueToStringFct)(void *, JSValue);
  84. typedef void   (*JSAStringToValueFct)(void *, char *, JSValue);
  85. typedef double (*JSAValueToDoubleFct)(void *, JSValue);
  86. typedef void   (*JSADoubleToValueFct)(void *, double, JSValue);
  87. typedef void   (*JSARegisterFunctionFct)(void *, char *name, JSANativeMethod);
  88. typedef void   (*JSASetErrorFct)(void *, char*);
  89. typedef void   (*JSAInitializeFct)(void *);
  90. typedef void   (*JSAExitFct)();
  91. typedef void   (*JSAUndefinedToValueFct)(void *, JSValue);
  92. typedef void   (*JSAEvalFct)(void*, char* text, JSValue retVal, long timeout);
  93.  
  94. #ifdef WIN32
  95. #define JSAEXPORT __declspec(dllexport)
  96. #else
  97. #define JSAEXPORT
  98. #endif
  99.  
  100. /* ---------- Environment --------------------- */
  101.  
  102. typedef struct _JSAEnv
  103. {
  104.     long                    jsaStructSize;
  105.     long                    jsaVersion;
  106.     void *                    jsaInst;
  107.     void *                    externalRef;
  108.     JSAValueTypeFct            vtypFct;
  109.     JSAValueToIntFct        vtoiFct;
  110.     JSAIntToValueFct        itovFct;
  111.     JSAValueToBoolFct        vtobFct;
  112.     JSABoolToValueFct        btovFct;
  113.     JSAValueToStringFct        vtosFct;
  114.     JSAStringToValueFct        stovFct;
  115.     JSAValueToDoubleFct        vtodFct;
  116.     JSADoubleToValueFct        dtovFct;
  117.     JSARegisterFunctionFct    regFct;
  118.     JSASetErrorFct            errFct;
  119.     JSAUndefinedToValueFct    utovFct;
  120.     JSAEvalFct                evalFct;
  121. } JSAEnv;
  122.     
  123. /* ---------- Interface ------------------------- */
  124.  
  125. /**
  126. The JSAMain function is called from within the JSA_INIT macro. It should be used
  127. to register all functions callable by the Extend Script SDK. It is called when the
  128. module has been loaded, which the SDK does on demand before calling the first
  129. function inside the module.
  130. */
  131. extern    void JSAEXPORT JSAMain(void);
  132.  
  133. /**
  134. The JSAExit function is called when the extension module is about to be unloaded.
  135. Here, the module may be deinitialized.
  136. */
  137. extern    void JSAEXPORT JSAExit(void);
  138.  
  139. /**
  140. Retrieve the type of a value. It is one of the JSAValueType enums.
  141. @param    v            the JSAValue to check
  142. @return                the type of the value
  143. */
  144. #define JSAGetValueType(v)    JSAEnvObj->vtypFct(JSAEnvObj,v)
  145.  
  146. /**
  147. Retrieve the value as a signed 32 bit integer quantity. Automatic conversion
  148. to the value is applied according to Javascript rules if necessary.
  149. @param    v            the JSAValue to convert
  150. @return                the integer value
  151. */
  152. #define JSAValueToInt(v)                JSAEnvObj->vtoiFct(JSAEnvObj,v)
  153.  
  154. /**
  155. Store an integer value into the given JSAValue.
  156.  
  157. @param    v            the JSAValue to receive the integer value
  158. @param    i            the integer value to store
  159. */
  160. #define JSAIntToValue(v,i)                JSAEnvObj->itovFct(JSAEnvObj,i,v)
  161.  
  162. /**
  163. Retrieve the value as a boolean quantity (zero or nonzero). Automatic conversion
  164. to the value is applied according to Javascript rules if necessary.
  165. @param    v            the JSAValue to convert
  166. @return                the boolean value
  167. */
  168. #define JSAValueToBool(v)                JSAEnvObj->vtobFct(JSAEnvObj,v)
  169.  
  170. /**
  171. Store an boolean value into the given JSAValue.
  172.  
  173. @param    v            the JSAValue to receive the boolean value (zero or nonzero)
  174. @param    b            the boolean value (zero or nonzero) to store
  175. */
  176. #define JSABoolToValue(v,b)                JSAEnvObj->btovFct(JSAEnvObj,b,v)
  177.  
  178. /**
  179. Retrieve the value as a zero terminated ASCII string. Automatic conversion
  180. to the value is applied according to Javascript rules if necessary.
  181. @param    v            the JSAValue to convert
  182. @return                the ASCII string
  183. */
  184. #define JSAValueToString(v)                JSAEnvObj->vtosFct(JSAEnvObj,v)
  185.  
  186. /**
  187. Store a zero terminated ASCII string value into the given JSAValue.
  188.  
  189. @param    v            the JSAValue to receive the string
  190. @param    s            the string to store
  191. */
  192. #define JSAStringToValue(v,s)            JSAEnvObj->stovFct(JSAEnvObj,s,v)
  193.  
  194. /**
  195. Retrieve the value as an eight byte floating point value. Automatic conversion
  196. to the value is applied according to Javascript rules if necessary.
  197. @param    v            the JSAValue to convert
  198. @return                the floating point value
  199. */
  200. #define JSAValueToDouble(v)                JSAEnvObj->vtodFct(JSAEnvObj,v)
  201.  
  202. /**
  203. Store an eight byte floating point value into the given JSAValue.
  204.  
  205. @param    v            the JSAValue to receive the floating point value
  206. @param    d            the floating point value to store
  207. */
  208. #define JSADoubleToValue(v,d)            JSAEnvObj->dtovFct(JSAEnvObj,d,v)
  209.  
  210. /**
  211. Set the given value to undefined.
  212.  
  213. @param    v            the JSAValue to be set to undefined.
  214. */
  215. #define JSAUndefinedToValue(v)            JSAEnvObj->utovFct(JSAEnvObj,v)
  216.  
  217. /**
  218. Register a function by name within the Javascript extension. Only registered functions can
  219. be called from within the Javascirpt extension modules. The function must be a JSANativeMethod.
  220. The location to register functions is within the JSAMain() function.
  221. @param    n            the function name. The name must follow Javascript naimg conventions.
  222. @param    f            the function itself (a JSANativeMethod)
  223. */
  224. #define JSARegisterFunction(n,f)        JSAEnvObj->regFct(JSAEnvObj,n,f)
  225.  
  226. /**
  227. Set a runtime error.
  228.  
  229. @param    text        the error message as a zero terminated ASCII string
  230. */
  231. #define JSASetError(text)                JSAEnvObj->errFct(JSAEnvObj,text)
  232.  
  233. /**
  234. Evaluate a Javascript scriptlet. The scriptlet is executed within the current runtime scope
  235. of Javascript. An optional JSAValue may be supplied to receive the return value. The given
  236. timeout is the timeout in milliseconds to wait for the engine. If the timeout elapses before
  237. this call returns, a runtime error is generated. Supplying 0 means that the scriptlet is
  238. run asynchronously; the call returns immediately, and the return value location must be NULL.
  239. A value of -1 means to wait forever, which should be the default.
  240. @param    text        the scriptlet code to run
  241. @param    retval        the optional return value (may be NULL for no return value)
  242. @param    timeout        the timeout in milliseconds. 0 returns immediately, -1 waits forever.
  243. */
  244. #define    JSAEval(text,retval,timeout)    JSAEnvObj->evalFct(JSAEnvObj,text,retval,timeout)
  245.  
  246. /**
  247. The structure supplied to allow for drawing inside a module.
  248. The Draw.getDrawInfo() method of the Extend Script SDK returns a long value which is really a
  249. pointer to a JSADrawInfo structure. The pointer may be retrieved by JSAValueToInt() and casted
  250. to a JSADrawInfo structure. The contents of the structure can be used to implement drawing
  251. in native code.
  252. */
  253. struct _JSADrawInfo
  254. {
  255.     /// The device context. This is a DC handle on Windows or a GrafPtr pointer on the Mac.
  256.     long        context;
  257.     /// The top left corner of the current drawing area.
  258.     long        left, top;
  259.     /// The bottom right corner of the current drawing area.
  260.     long        right, bottom;
  261. };
  262.  
  263. typedef struct _JSADrawInfo JSADrawInfo;
  264.  
  265.  
  266. /* ---------- Implementation ---------------- */
  267.  
  268. extern    JSAEnv    *JSAEnvObj;
  269. extern    void JSAEXPORT JSAEntry(JSAEnv *env);
  270.  
  271. #define JSA_INIT            \
  272.                             \
  273. JSAEnv    *JSAEnvObj;            \
  274.                             \
  275. void main()                    \
  276. {                            \
  277. }                            \
  278.                             \
  279. void JSAEXPORT JSAEntry(JSAEnv *env)    \
  280. {                            \
  281.     JSAEnvObj = env;        \
  282.     JSAMain();                \
  283. }                            \
  284.  
  285. #ifdef __cplusplus
  286. }
  287. #endif
  288.  
  289. #endif
  290.